package com.dc.system.controller;

import com.dc.common.model.BaseModel;
import com.dc.system.model.ApprovalHistory;
import com.dc.system.model.ApprovalModel;
import com.dc.system.model.ApprovalProcess;
import com.dc.system.model.ApprovalProviso;
import com.dc.system.service.ApprovalService;
import com.wordnik.swagger.annotations.ApiImplicitParam;
import com.wordnik.swagger.annotations.ApiImplicitParams;
import com.wordnik.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: ApprovalController
 * @Author: ChenXueLi
 * @Date: 2018-05-04 11:51
 */
@Controller
@RequestMapping("/approval")
public class ApprovalController {

    @Autowired
    private ApprovalService approvalService;

    @ApiOperation(value = "添加一个审核模板", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "审批模板的名称", required = true, paramType = "query"),
            @ApiImplicitParam(name = "approver_type", value = "审批人类别（0指定人，1指定职务，2指定部门）", required = true, paramType = "query"),
            @ApiImplicitParam(name = "approval_order", value = "审批顺序（0顺序 1同步）", required = true, paramType = "query"),
            @ApiImplicitParam(name = "approval_pass_type", value = "审批通过的类型(0全部通过才算通过 1一人通过就算通过 2按自定比例通过才算通过)", required = true, paramType = "query"),
            @ApiImplicitParam(name = "approval_pass_proportion", value = "通过需要的比例", required = false, paramType = "query"),
            @ApiImplicitParam(name = "proviso_ids", value = "条件审批（多个条件用,分隔）", required = false, paramType = "query")
    })
    @RequestMapping("/addApprovalModel")
    @ResponseBody
    public BaseModel addApprovalModel(ApprovalModel approvalModel, BaseModel baseModel, HttpServletRequest request) throws Exception{
        return approvalService.addApprovalModel(baseModel, approvalModel, request);
    }

    @ApiOperation(value = "添加一个审核模板分条件", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "审批模板的名称", required = true, paramType = "query"),
            @ApiImplicitParam(name = "approver_type", value = "审批人类别（0指定人，1指定职务，2指定部门）", required = true, paramType = "query"),
            @ApiImplicitParam(name = "approval_order", value = "审批顺序（0顺序 1同步）", required = true, paramType = "query"),
            @ApiImplicitParam(name = "approval_pass_type", value = "审批通过的类型(0全部通过才算通过 1一人通过就算通过 2按自定比例通过才算通过)", required = true, paramType = "query"),
            @ApiImplicitParam(name = "approval_pass_proportion", value = "通过需要的比例", required = false, paramType = "query"),
            @ApiImplicitParam(name = "proviso_ids", value = "条件审批（多个条件用,分隔）", required = false, paramType = "query")
    })
    @RequestMapping("/addApprovalProviso")
    @ResponseBody
    public BaseModel addApprovalProviso(ApprovalProviso approvalProviso, BaseModel baseModel, HttpServletRequest request) throws Exception{
        return approvalService.addApprovalProviso(baseModel, approvalProviso, request);
    }

    @ApiOperation(value = "添加一个审核流程", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "approval_model_id", value = "模板id编号", required = true, paramType = "query"),
            @ApiImplicitParam(name = "approver", value = "审批人（多人用,分隔）", required = true, paramType = "query"),
            @ApiImplicitParam(name = "approval_proviso_value", value = "分条件的值", required = false, paramType = "query")
    })
    @RequestMapping("/addApprovalProcess")
    @ResponseBody
    public BaseModel addApprovalProcess(ApprovalProcess approvalProcess, BaseModel baseModel, HttpServletRequest request) throws Exception{
        return approvalService.addApprovalProcess(baseModel,approvalProcess,request);
    }

    @ApiOperation(value = "进行审批操作", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "process_id", value = "流程的编号", required = true, paramType = "query"),
            @ApiImplicitParam(name = "approval_state", value = "给的评定", required = true, paramType = "query")
    })
    @RequestMapping("/examine")
    @ResponseBody
    public BaseModel examine(ApprovalHistory approvalHistory, BaseModel baseModel, HttpServletRequest request) throws Exception{
        return approvalService.examine(approvalHistory,baseModel,request);
    }
}
